import {BaseCard} from '../models/Card';
import {CardSuit, MapCardConfig} from '../GameDef';
import {CardPoolMgr} from '../manager/CardPoolMgr';

type RuleMap = {
    [key: string]: (cardPool, cardCfg: MapCardConfig, ...args) => BaseCard;

}

/**
 * 地图规则类, 用于生成地图股则定义
 */

export class GenerateMapRule {
    random(cardPool:CardPoolMgr, cardCfg?:MapCardConfig, ...args) {
        const card = cardPool.getRandomCard(card => !card.isUsed);
        
        return card;
    }

    fix(cardPool:CardPoolMgr, cardCfg:MapCardConfig, ...args) {
        const card = cardPool.getCardByValue(cardCfg.cardid);
        if (card.isUsed) {
            return this.random(cardPool, cardCfg);
        } else {
            return card;
        }
    }


    color(cardPool:CardPoolMgr,cardCfg: MapCardConfig, ...args: string[]){
        let color= args[0];
        if (!color) {
            return this.random(cardPool);
        }

        let colorNum = CardSuit[color];

        return cardPool.getRandomCard(card => !card.isUsed && card.suit == colorNum);
    }

    number(cardPool:CardPoolMgr,cardCfg:MapCardConfig,...args:string[]){
        if (args.length < 2) {
            return this.random(cardPool);
        }
        let numberLowerLimit = Number(args[0]);
        let numberUpperLimit = Number(args[1]);
        return cardPool.getRandomCard(card =>!card.isUsed && card.rank >= numberLowerLimit && card.rank <= numberUpperLimit);
    }

    numberCards(cardPool:CardPoolMgr,cardCfg:MapCardConfig,...args:string[]){

        return cardPool.getRandomCard(card =>!card.isUsed && card.rank == cardCfg.cardid);
    }

    headCards(cardPool:CardPoolMgr,cardCfg:MapCardConfig,...args:string[]){

    }
}